

***************
*** Table 6 ***
***************

clear all

*Set the folder where data are
cd ""

use B2_correct,clear

*drop HH and workers observed only once
drop if honeobsfyr==1
drop if wnyrsp==1

bysort dhcode year: gen counter = _n == 1   // create a dummy variable 1 for first HH obs in a year, 0 otherwise
by dhcode: replace counter = sum(counter)     // sum the 1s and 0s only within HH, hence the first year that first member in HH is observed is 1, the second year is 2 etc
by dhcode: egen hhnyrsp = max(counter)     //  within HH replaces all values with the highest to give the HH number of years in the UHS
label var hhnyrsp "HH total number of years in UHS panel"
tab hhnyrsp 
drop if hhnyrsp==1

xtset dhcode year

*** county specific trends
quiet tab countyid, gen(countytrend)
quiet for num 1/658: replace countytrendX=countytrendX*year

*** city specific trends
quiet tab cityid, gen(citytrend)
quiet for num 1/194: replace citytrendX=citytrendX*year
replace citygovbalgdp=. if citygovbalgdp<-20
gen lncitygovexp=ln(citygovexp)

** tabulate industries because xtivreg2 does not take factor variables
set more off
tab industryH, gen(indH)
tab industryS, gen(indS)
tab occupationH, gen(occH)
tab occupationS, gen(occS)
tab maritstatusH, gen(marH)
tab maritstatusS, gen(marS)
tab educH, gen(edH)
tab educS, gen(edS)
tab educ2H, gen(ed2H)
tab educ2S, gen(ed2S)


*** gen provinceXtime FE since xtivreg does not use factor variables
set more off
egen provxyr = group(provid year)
tab provxyr, gen(pxy)
egen cityxyr = group(cityid year)
tab cityxyr, gen(cxy)

drop if hMWshare==.


*Controls
global xhh familysize houseown genderH genderS ageH ageS age2H age2S i.educH i.educS i.educ2H i.educ2S wexperH wexperS wexper2H wexper2S migrH migrS migr2H migr2S i.industryH i.industryS i.occupationH i.occupationS i.maritstatusH i.maritstatusS
global xhh1 familysize genderH genderS ageH ageS age2H age2S i.educH i.educS i.educ2H i.educ2S wexperH wexperS wexper2H wexper2S migrH migrS migr2H migr2S i.industryH i.industryS i.occupationH i.occupationS i.maritstatusH i.maritstatusS

global xhhiv familysize houseown genderH genderS ageH ageS age2H age2S wexperH wexperS wexper2H wexper2S migrH migrS migr2H migr2S hhrealpension hhrealpropinc hhrealhsln

*City
global xcity lnrealcitygdp lnrealcitysalary cityunemplrate citypop       
global xcityge lnrealcitygdp lnrealcitysalary cityunemplrate citypop lncitygovexp         
global xyr year2 year3 year4 year5 year6 year7 year8



* Children, onechild, malechild
replace malechild=0 if malechild==.

drop child
drop children
gen children=1 if nchildren>0
replace children=0 if nchildren==0
gen onechild=nchildren==1 if !missing(nchildren)
replace onechild=. if nchildren>1
gen adultmalechild=adultchildhh*malechild
replace adultmalechild=0 if adultmalechild==.

*child
gen hhrlichild=hhreallabtrincnp*children
gen effrmwchild=effrealmw*children

*malechild
gen hhrlimchild=hhreallabtrincnp*malechild
gen effrmwmchild=effrealmw*malechild

*adultchild
replace adultchildhh=0 if adultchildhh==.
gen hhrliadult=hhreallabtrincnp*adultchildhh
gen effrmwadult=effrealmw*adultchildhh


*drop 2002 for mechancial correlation
drop if year==2002



set matsize 1000


*Table 6

est clear 
set more off
xtivreg2 hhrealcons (hhreallabinc hhrlichild = effrealmw effrmwchild) children $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare==0,  fe robust cluster(countyid)
est sto m1
xtivreg2 hhrealcons (hhreallabinc hhrlichild = effrealmw effrmwchild) children  $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare>0.5,  fe robust cluster(countyid)
est sto m2
xtivreg2 hhrealcons (hhreallabinc hhrlichild = effrealmw effrmwchild) children  $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS*  countytrend* if hMWshare>0.75, fe robust cluster(countyid)
est sto m3
xtivreg2 hhrealcons (hhreallabinc hhrlichild hhrlimchild = effrealmw effrmwchild effrmwmchild) children malechild $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare==0, fe robust cluster(countyid)
est sto m4
xtivreg2 hhrealcons (hhreallabinc hhrlichild hhrlimchild = effrealmw effrmwchild effrmwmchild) children malechild $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare>0.5, fe robust cluster(countyid)
est sto m5
xtivreg2 hhrealcons (hhreallabinc hhrlichild hhrlimchild = effrealmw effrmwchild effrmwmchild) children malechild $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare>0.75, fe robust cluster(countyid)
est sto m6
xtivreg2 hhrealcons (hhreallabinc hhrlichild hhrliadult = effrealmw effrmwchild effrmwadult) children adultchildhh $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare==0, fe robust cluster(countyid)
est sto m7
xtivreg2 hhrealcons (hhreallabinc hhrlichild hhrliadult = effrealmw effrmwchild effrmwadult) children adultchildhh $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare>0.5, fe robust cluster(countyid)
est sto m8
xtivreg2 hhrealcons (hhreallabinc hhrlichild hhrliadult = effrealmw effrmwchild effrmwadult) children adultchildhh $xhhiv $xcity pxy* edH* edS* ed2H* ed2S* indH* indS* occH* occS* marH* marS* countytrend* if hMWshare>0.75, fe robust cluster(countyid)
est sto m9

estout m1 m2 m3 m4 m5 m6 m7 m8 m9 using "Table_6.tex", style(tex) cells(b(fmt(3)) se(star par fmt(3))) delim("&") numbers starlevels(* 0.10 ** 0.05 *** 0.01) ///
collabels( , none) mlabels("$ S=0 $" "$ S>0.5 $" "$ S>0.75 $" "$ S=0 $" "$ S>0.5 $" "$ S>0.75 $" "$ S=0 $" "$ S>0.5 $" "$ S>0.75 $") ///
mgroups(, lhs(Dep.var.: Household Consumption) pattern(1 0 0 1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span})) ///
stats(N N_clust N_g idp, fmt(0 0 0 3 3) label(Obs. "N clusters" "N households" "Weak instr. (pval)")) ///
keep(hhreallabinc hhrlichild hhrlimchild hhrliadult) varlabels(hhreallabinc "Household labor income" hhrlichild "Household labor income*Child(ren)" hhrlimchild "Household labor income*Male Child" hhrliadult "Household labor income*Adult Child") varwidth(20) modelwidth(10) ///
prehead("\begin{table}[tbhp] \centering \resizebox{\textwidth}{!} { \begin{tabular}{l*{9}{c}}" \toprule) posthead(\cmidrule(rl){2-4}\cmidrule(rl){5-7}\cmidrule(rl){8-10} \\)  ///
prefoot( \\ City-level controls & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes  \\ Household FE & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes  ///
\\  Prov $\times$ year FE & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes \\ County Trend & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes & Yes \\ ) postfoot( \bottomrule "\end{tabular} } \end{table} ") replace





